package com.hy.controller;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * author: Mr.Du
 * Date: 2022/10/20
 * Time: 10:56
 */
@RestController
@RequestMapping("/metadata")
public class MetaDataController {
    
    @Resource
    private DiscoveryClient discoveryClient;
    
    @GetMapping("/show")
    public Map<String,String> getMetaData(){
        List<ServiceInstance> instances = discoveryClient.getInstances("hy-service-product");
        ServiceInstance serviceInstance = instances.get(0);
        Map<String, String> metadata = serviceInstance.getMetadata();
        return metadata;
    }
}
